ELF unexec: Drive from PT_LOAD header rather than sections
authorAlan Modra <amodra@gmail.com>
Sun, 8 Nov 2015 17:29:00 +0000 (09:29 -0800)
committerRob Browning <rlb@defaultvalue.org>
Mon, 18 Jan 2016 21:17:58 +0000 (15:17 -0600)
commit75dc7e12d73ad8c1bf9583515e41913980883dbe
treed2b67e8cc62507684fd3dac4cea5b358e67224fa
parentf9d91515971443b754b9c9eaac45a293d0e620c1
ELF unexec: Drive from PT_LOAD header rather than sections

Emacs should build on ppc64el.  A problem with the bss has been fixed.

This upstream patch has been added [7/10]:

  ELF unexec: Drive from PT_LOAD header rather than sections

  This rewrites bss handling in the ELF unexec code.  Finding bss
  sections by name results in complicated code that
  - does not account for all names of possible bss sections,
  - assumes specific ordering of bss sections,
  - can wrongly choose a SHT_NOBITS section not in the bss segment,
  - incorrectly calculates bss size (no accounting for alignment gaps),
  - assumes .data and .bss are in the same segment.

  All of these problems and more are solved by finding the bss segment
  in PT_LOAD headers, ie. the address range included in p_memsz but not
  p_filesz of the last PT_LOAD header, then matching SHT_NOBITS sections
  in that address range.

  * unexelf.c: Delete old ppc comment.
  (OLD_PROGRAM_H): Define.
  (round_up): Delete.
  (unexec): Don't search for bss style sections by name.  Instead,
  use the last PT_LOAD header address range covered by p_memsz
  but not p_filesz and match any SHT_NOBITS section in that
  address range.  Simplify initialisation of section header vars.
  Don't assume that section headers are above bss segment.  Move
  copying of bss area out of section loop.  Align .data2 section
  to 1, since it now covers the entire bss area.  For SHT_NOBITS
  sections in the bss segment, leave sh_addr and sh_addralign
  unchanged, but correct sh_offset.  Clear memory corresponding
  to SHT_NOBITS .plt section.  Delete comment and hacks for
  sections partly overlapping bss range now that the full range
  is properly calculated.  Delete now dead .sbss code.
  (Bug#20614)

Origin: upstream, commit: 0d6442265e5b709af5eebedf8f0d6b82974f4c31
Bug: http://debbugs.gnu.org/20614
Bug-Debian: http://bugs.debian.org/808347
Added-by: Rob Browning <rlb@defaultvalue.org>
src/unexelf.c